const config = require("./mysqlConfig");

const mysql = require("mysql");

const pool = mysql.createPool(config);

const query = (sqlStatement) => {
  return new Promise((resolve, reject) => {
    pool.getConnection((error, connection) => {
      if (error) {
        console.log(error);
        return;
      }
      connection.query(sqlStatement, (error, results) => {
        connection.release();
        if (error) {
          reject(error);
        }
        resolve(results);
      });
    });
  });
};

module.exports = { query };
